package com.tinama.jedis01.nio;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.DatagramChannel;
import java.util.Date;
import java.util.Scanner;

/**
 * @author lgc
 * @createDate 2021/1/19 - 10:24
 */
public class SendTest {
    public static void main(String[] args) throws IOException {
        DatagramChannel dc = DatagramChannel.open();
        dc.configureBlocking(false);
        ByteBuffer byteBuffer = ByteBuffer.allocate(1024);
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            String next = scanner.next();
            byteBuffer.put((new Date().toString()+":\n"+next).getBytes());
            byteBuffer.flip();
            dc.send(byteBuffer,new InetSocketAddress("127.0.0.1",8888));
            byteBuffer.clear();
        }
        dc.close();
    }
}
